22
Beginner’s Guide to Code Algorithms
22
2.4 BUILDING A “GAME” FROM A “WIDGET”
What you have so far is a widget. You enter something and the program produces
something based on your input. In order to make it into a game, you need to put in
a few more frills. The most important of which is a scoring system. This feeling
of “win” or “loss” is what makes a widget interesting and will draw people to
“play” it.
This is done by writing code. You already have a great start with Macro1. Let’s go
back to the code and continue to build.
Go to your Project Explorer window and double-click on Module1. If this window
is not visible, simply select “Project Explorer” from the “View” menu.
FIGURE 2.19 Project Explorer.
Let us now write the piece of code that launches the game.
This is simple—it shows the form we have created and initializes the variables we
are going to use to control the game
Sub InitFormFirst()
Dim cCont As Control
UserForm1.Show
For i = 1 To 3
For j = 1 To 3
UserForm1.Controls("TextBox" & (i - 1) * 3 + j) = ""
UserForm1.Controls("TextBox" & (i - 1) * 3 + j).BackColor = &HFFFFFF
Next j
Next i
UserForm1.Controls("TextBox11") = "0"
UserForm1.Controls("TextBox12") = "0"
UserForm1.Controls("TextBox13") = "0"
UserForm1.Controls("TextBox14") = "0"
UserForm1.Controls("TextBox10") = "Click Play To Start"
End Sub
FIGURE 2.20 InitFormFirst.